home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dvips / fontdef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-05  |  3.1 KB  |  112 lines

  1. /*
  2.  *  Stores the data from a font definition into the global data structures.
  3.  *  A routine skipnop is also included to handle nops and font definitions
  4.  *  between pages.
  5.  */
  6. #include "structures.h" /* The copyright notice in that file is included too! */
  7. /*
  8.  *   These are the external routines we call.
  9.  */
  10. extern shalfword dvibyte() ;
  11. extern integer signedquad() ;
  12. extern void error() ;
  13. /*
  14.  *   The external variables we use:
  15.  */
  16. extern char *nextstring, *maxstring ;
  17. extern integer mag ;
  18. #ifdef DEBUG
  19. extern integer debug_flag;
  20. #endif  /* DEBUG */
  21. extern int actualdpi ;
  22. extern real alpha ;
  23. extern fontmaptype *ffont ;
  24. extern fontdesctype *fonthead ;
  25. /*
  26.  *   We use malloc here:
  27.  */
  28. char *malloc() ;
  29. /*
  30.  *   fontdef takes a font definition in the dvi file and loads the data
  31.  *   into its data structures.
  32.  */
  33. void
  34. fontdef()
  35. {
  36.    register integer i, j, fn ;
  37.    register fontdesctype *fp, *fpp ;
  38.    register fontmaptype *cfnt ;
  39.  
  40.    fn = dvibyte() ;
  41.    for (cfnt=ffont; cfnt; cfnt = cfnt->next)
  42.       if (cfnt->fontnum == fn) goto alreadydefined ;
  43.    fp = (fontdesctype *)malloc(sizeof(fontdesctype)) ;
  44.    cfnt = (fontmaptype *)malloc(sizeof(fontmaptype)) ;
  45.    if (fp==NULL || cfnt==NULL)
  46.       error("! ran out of memory") ;
  47.    cfnt->next = ffont ;
  48.    ffont = cfnt ;
  49.    cfnt->fontnum = fn ;
  50.    fp->psname = 0 ;
  51.    fp->loaded = 0 ;
  52.    fp->checksum = signedquad() ;
  53.    fp->scaledsize = signedquad() ;
  54.    fp->designsize = signedquad() ;
  55.    fp->thinspace = fp->scaledsize / 6 ;
  56.    fp->resfont = NULL ;
  57.    fp->localfonts = NULL ;
  58.    fp->dpi = (halfword)((float)mag*(float)fp->scaledsize*DPI/
  59.          ((float)fp->designsize*1000.0)+0.5) ;
  60.    i = dvibyte() ; j = dvibyte() ;
  61.    if (nextstring + i + j > maxstring)
  62.       error("! out of string space") ;
  63.    fp->area = nextstring ;
  64.    for (; i>0; i--)
  65.       *nextstring++ = dvibyte() ;
  66.    *nextstring++ = 0 ;
  67.    fp->name = nextstring ;
  68.    for (; j>0; j--)
  69.       *nextstring++ = dvibyte() ;
  70.    *nextstring++ = 0 ;
  71. #ifdef DEBUG
  72.    if (dd(D_FONTS))
  73.       (void)fprintf(stderr,"Defining font (%s) %s at %.1fpt\n",
  74.          fp->area, fp->name, (real)fp->scaledsize/(alpha*0x100000)) ;
  75. #endif /* DEBUG */
  76.    for (fpp=fonthead; fpp; fpp=fpp->next)
  77.       if (fp->scaledsize==fpp->scaledsize &&
  78.             strcmp(fp->name,fpp->name)==0 && strcmp(fp->area,fpp->area)==0) {
  79. #ifdef DEBUG
  80.          if (dd(D_FONTS))
  81.             (void)fprintf(stderr,"(Already known.)\n") ;
  82. #endif /* DEBUG */
  83.          free((char *)fp) ;
  84.          fp = fpp ;
  85.          goto alreadyknown ;
  86.       }
  87.    fp->next = fonthead ;
  88.    fonthead = fp ;
  89. alreadyknown:
  90.    cfnt->desc = fp ;
  91.    return ;
  92. alreadydefined:
  93. /* A DVI file will not define a font twice; but we may be scanning
  94.  * a font definition twice because a new section has started,
  95.  * or because of collated copies. */
  96.       skipover(12) ;
  97.       skipover(dvibyte()+dvibyte()) ;
  98. }
  99.  
  100. /*
  101.  *   The next routine handles nops or font definitions between pages in a
  102.  *   dvi file.  Returns the first command that is not a nop or font definition.
  103.  */
  104. int
  105. skipnop()
  106. {
  107.   register int cmd ;
  108.   while ((cmd=dvibyte())==138||cmd==243)
  109.     if (cmd==243) fontdef() ;
  110.   return(cmd) ;
  111. }
  112.